/*
 * @Author: error: error: git config user.name & please set dead value or install git && error: git config user.email & please set dead value or install git & please set dead value or install git
 * @Date: 2025-04-02 14:45:43
 * @LastEditors: jqm123 2289662078@qq.com
 * @LastEditTime: 2025-08-22 15:35:37
 * @FilePath: index.js
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
/*
 * @description:
 * @param:
 * @return:
 */
import Vue from "vue";
import VueRouter from "vue-router";
import tabbar from "../layout/tabbar.vue";
import store from "@/store/index";
import { zxcxGetUserInfo, isZxcxAPP, isWechat } from "@/utils/zxcxWebkits.js";
import { Toast } from "vant";

Vue.use(VueRouter);

const routes = [
  {
    path: "/",
    name: "layout",
    redirect: "/home",
    component: tabbar,
    children: [
      {
        path: "/home",
        name: "home",
        component: () => import("@/views/home.vue"),
        meta: {
          name: "首页",
          KeepAlive: true,
        },
      },
      {
        path: "/store",
        name: "store",
        component: () => import("@/views/store.vue"),
        meta: {
          name: "门店",
          KeepAlive: true,
        },
      },
      {
        path: "/serve",
        name: "serve",
        component: () => import("@/views/serve.vue"),
        meta: {
          name: "服务管家",
          KeepAlive: true,
        },
      },
      {
        path: "/vip",
        name: "vip",
        component: () => import("@/views/vip.vue"),
        meta: {
          name: "会员",
          KeepAlive: true,
        },
      },
      {
        path: "/my",
        name: "my",
        component: () => import("@/views/my.vue"),
        meta: {
          name: "我的",
          KeepAlive: true,
        },
      },
    ],
  },
  {
    path: "/addCar",
    name: "addCar",
    component: () => import("@/subpages/addCar.vue"),
    meta: {
      name: "添加爱车",
    },
  },
  {
    path: "/washCar",
    name: "washCar",
    component: () => import("@/subpages/washCar.vue"),
    meta: {
      name: "洗车",
    },
  },
  {
    path: "/baoyang",
    name: "baoyang",
    component: () => import("@/subpages/baoyang.vue"),
    meta: {
      name: "保养",
    },
  },
  {
    path: "/luntai",
    name: "luntai",
    component: () => import("@/subpages/luntai.vue"),
    meta: {
      name: "轮胎",
    },
  },
  {
    path: "/storeDetail",
    name: "storeDetail",
    component: () => import("@/subpages/storeDetail.vue"),
    meta: {
      name: "门店详情",
    },
  },
  {
    path: "/order",
    name: "order",
    component: () => import("@/subpages/order.vue"),
    meta: {
      name: "全部订单",
    },
  },
  {
    path: "/orderDetail",
    name: "orderDetail",
    component: () => import("@/subpages/otherPages/orderDetail.vue"),
    meta: {
      name: "订单详情",
    },
  },
  {
    path: "/makeSure",
    name: "makeSure",
    component: () => import("@/subpages/otherPages/makeSureOrder.vue"),
    meta: {
      name: "确认订单",
    },
  },
  {
    path: "/location",
    name: "location",
    component: () => import("@/subpages/location.vue"),
    meta: {
      name: "选择位置",
    },
  },
  {
    path: "/search",
    name: "search",
    component: () => import("@/subpages/search.vue"),
    meta: {
      name: "搜索",
    },
  },
  {
    path: "/refund",
    name: "refund",
    component: () => import("@/subpages/refund.vue"),
    meta: {
      name: "退款",
    },
  },
  {
    path: "/weiquan",
    name: "weiquan",
    component: () => import("@/subpages/weiquan.vue"),
    meta: {
      name: "维权通道",
    },
  },
  {
    path: "/addWeiquan",
    name: "addWeiquan",
    component: () => import("@/subpages/otherPages/addWeiquan.vue"),
    meta: {
      name: "我要维权",
    },
  },
  {
    path: "/myWeiquan",
    name: "myWeiquan",
    component: () => import("@/subpages/myWeiquan.vue"),
    meta: {
      name: "我的维权",
    },
  },
  {
    path: "/chat",
    name: "chat",
    component: () => import("@/subpages/chat.vue"),
    meta: {
      name: "安心修智能管家",
    },
  },
  {
    path: "/setting",
    name: "setting",
    component: () => import("@/subpages/setting.vue"),
    meta: {
      name: "设置",
    },
  },
  {
    path: "/address",
    name: "address",
    component: () => import("@/subpages/address.vue"),
    meta: {
      name: "收货信息",
    },
  },
  {
    path: "/addressDetail",
    name: "addressDetail",
    component: () => import("@/subpages/otherPages/addressDetail.vue"),
    meta: {
      name: "新增/编辑收货信息",
    },
  },
  {
    path: "/systemMessage",
    name: "systemMessage",
    component: () => import("@/subpages/systemMessage.vue"),
    meta: {
      name: "服务通知",
    },
  },
  {
    path: "/customer",
    name: "customer",
    component: () => import("@/subpages/customer.vue"),
    meta: {
      name: "客服消息",
    },
  },
  {
    path: "/serveDetail",
    name: "serveDetail",
    component: () => import("@/subpages/otherPages/serveDetail.vue"),
    meta: {
      name: "服务详情",
    },
  },
  {
    path: "/comment",
    name: "comment",
    component: () => import("@/subpages/otherPages/comment.vue"),
    meta: {
      name: "评价",
    },
  },
  {
    path: "/allVipUse",
    name: "allVipUse",
    component: () => import("@/subpages/allVipUse.vue"),
    meta: {
      name: "所有适用门店",
    },
  },
  {
    path: "/confirmVipOrder",
    name: "confirmVipOrder",
    component: () => import("@/subpages/confirmVipOrder.vue"),
    meta: {
      name: "确认vip订单",
    },
  },
  {
    path: "/404",
    name: "404",
    component: () => import("@/views/404.vue"),
    meta: {
      name: "404",
    },
  },
  {
    path: "/paySuccess",
    name: "paySuccess",
    component: () => import("@/views/paySuccess.vue"),
    meta: {
      name: "支付成功",
    },
  },
  {
    path: "/payError",
    name: "payError",
    component: () => import("@/views/payError.vue"),
    meta: {
      name: "支付失败",
    },
  },
  {
    path: "/hotActive",
    name: "hotActive",
    component: () => import("@/subpages/hotActive.vue"),
    meta: {
      name: "爆款活动",
    },
  },
  {
    path: "/writeOfforder",
    name: "writeOfforder",
    component: () => import("@/subpages/otherPages/writeOfforder.vue"),
    meta: {
      name: "安心修核销",
    },
  },
  {
    path: "/coupon",
    name: "coupon",
    component: () => import("@/subpages/coupon.vue"),
    meta: {
      name: "我的券包",
    },
  },
  {
    path: "/audio",
    name: "audio",
    component: () => import("@/subpages/otherPages/audio.vue"),
    meta: {
      name: "直播",
    },
  },
  {
    path: "/couponWriteOff",
    name: "couponWriteOff",
    component: () => import("@/subpages/otherPages/couponWriteOff.vue"),
    meta: {
      name: "消费券核销",
    },
  },
  // {
  //   path: '/about',
  //   name: 'about',
  //   // route level code-splitting
  //   // this generates a separate chunk (about.[hash].js) for this route
  //   // which is lazy-loaded when the route is visited.
  //   component: () => import(/* webpackChunkName: "about" */ '../views/AboutView.vue')
  // }import { isZxcxApp } from './../utils/common';
];

const router = new VueRouter({
  mode: "hash",
  base: process.env.BASE_URL,
  routes,
});

router.beforeEach(async (to, from, next) => {
  if (from.fullPath === "/") {
    if (isZxcxAPP()) {
      let res = await zxcxGetUserInfo();
      let userInfo = JSON.parse(res);

      await store.dispatch("user/getInfo", userInfo.userId);
      next();
    } else if (process.env.NODE_ENV == "development") {
      // await store.dispatch(
      //   "user/getInfo",
      //   "b47f15ac-09ef-11ee-b9d1-286ed489a937"
      // );
      await store.dispatch(
        "user/getInfo",
        "b47f15ac-09ef-11ee-b9d1-286ed489a937"
      );

      next();
    } else if (to.path == "/hotActive" && isWechat()) {
      next();
    } else {
      Toast({
        message: "请在掌心长兴打开",
        duration: 0,
        forbidClick: true,
      });
      next();
    }
  } else {
    next();
  }
});

export default router;
